import 'package:flutter/material.dart';

main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "list demo",
      home: MyHomePage(
        title: "首页",
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool empty = false;
  final _controller = FixedExtentScrollController();
  final List<String> items = List.generate(100, (i) => "Item ${i + 1}");
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: GestureDetector(
            child: Text(widget.title),
            onTap: () {
              if (!empty) {
                // animateTo动画跳转
                _controller.animateTo(-20,
                    duration: const Duration(seconds: 2), curve: Curves.ease);
              }
            },
          ),
        ),
        body: RefreshIndicator(
          onRefresh: () => Future.delayed(const Duration(seconds: 3)),
          child: empty
              ? ListView(
                  children: [
                    Container(
                      height: 400,
                      color: Colors.blue,
                      child: const Text("no data"),
                    ),
                  ],
                )
              : Scrollbar(
                  controller: _controller,
                  child: ListWheelScrollView(
                      controller:
                          _controller, // 注意：使用FixedExtentScrollPhysics时，controller必须是FixedExtentScrollController
                      itemExtent: 60,
                      overAndUnderCenterOpacity: 0.8, // 除了中间外的其他元素的透明度
                      diameterRatio: 0.5, // 每一项的旋转角度
                      useMagnifier: true,
                      physics: const FixedExtentScrollPhysics(),
                      onSelectedItemChanged: (value) => // print(value),
                      children: items
                          .map((e) => Container(
                                alignment: Alignment.center,
                                color: Colors.blue,
                                child: Text(e),
                              ))
                          .toList())),
        ));
  }
}
